$(function(){
    "use strict";
    // 当点击直接投入的时候
    $('.directInto_box>p').click(function(){
        $(this).siblings('ul.directInto_list').toggleClass('active')
    })
    //当点击核算确定的时候
    $('#check').on('click','.cancel_btn',function(){
        $('#check').removeClass('active')
    })
    // 点击出现搜索框
    $('.hidden_box_showBox').click(function(){
        $(this).siblings('.hidden_box_hiddenBox').toggleClass('active')
        if($(this).children('i').hasClass('icon-jiantou')){
            $(this).children('i').removeClass('icon-jiantou').addClass('icon-jiantou-top')
        }else{
            $(this).children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        }
    })
    // 当确定搜索时
    $('.hiddenBox_list_btn').on('click','button',function(){
        $('.hidden_box_hiddenBox').removeClass('active')
        $('.hidden_box_showBox').children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        if($(this).html() == '确定'){
            // $('#dateVal').html(window.query_year||'全部')
            let time = $(this).closest('.hidden_box_hiddenBox').find('[data-query="time"]').val()

            window.location.href=`/Power/index.html?time=${time}`
        }else{
            // window.query_year = null
        }
    })
    //当点击查看记录时
    $('#table_table').on('click','.look_record_btn',function(e){
        e.preventDefault()
        $(this).siblings('.tip_hiddenBox').addClass('active')
    })
    // 当点击工时记录中确认按钮时
    $('#table_table').on('click','.work_record_box>.btn',function(e){
        e.preventDefault()
        $(this).parent().removeClass('active')
    })
    //全选的功能
    $('#checkAll').on('click',function(){
        let checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for(let i=0;i<checkboxs.length;i++){
            let checkbox=checkboxs[i];
            if(checkbox.disabled){
                // colnsole.log(11)
                continue
            }else{
                checkbox.checked=this.checked;
            }
        }
    })
    $('#table_table').on('click','input[type=checkbox]:not("#checkAll")',function(){
        "use strict";
        var isCheckedAll = true;
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                isCheckedAll = false;
                break;
            }
        }
        $('#checkAll')[0].checked = isCheckedAll;
    })

    /*当点击添加按钮时*/
    $('.operation_btn').on('click','a',function(e){
        e.preventDefault()
        if( $(this).html() == '添加' ){
            var add_people = $(this).attr('href')
            $(`[lll=${add_people}]`).addClass('active')
        }
        if( $(this).html() == '核算' ){
            var checkboxs =$('input[type=checkbox]:not("#checkAll")');
            var len = 0;
            let hs_arr = [];
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择人员！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }else{
                for (let hsi = 0; hsi < checkboxs.length; hsi++) {
                    if (checkboxs[hsi].checked) {
                        hs_arr.push( $(checkboxs[hsi]).closest('tr[data-index]').attr('data-index') )
                    }else{
                        continue;
                    }
                }
                $.ajax({
                    url:'/Admin/Power/calCulPow',
                    type:'get',
                    data:{
                        id:hs_arr
                    },
                    success:function(data){
                        if(data.code==1){
                            window.location.href='/Admin/Power/index'
                        }else{
                            $('#check').find('.check_success_num').html(data.success)
                            $('#check').find('.check_error_num').html(data.fail)
                            $('#check').find('.check_error_Reason').html(data.msg)
                            $(add_people).addClass('active')
                        }
                    }
                })
            }
            var add_people = $(this).attr('href')
            $(add_people).addClass('active')
        }
        if( $(this).html() == '批量导入' ){
            let showbox_id = $(this).attr('href');
            $(showbox_id).addClass('active')
        }
        if( $(this).html() == '批量删除' ){
            var checkboxs =$('input[type=checkbox]:not("#checkAll")');
            var len = 0;
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择人员！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }
            let _delete = $(this).attr('href');
            $(_delete).addClass('active')
        }
    })
    // 批量删除
    $('#delete .delete_tip_btn_box').on('click','button',function(){
        "use strict";
        let delete_arr = [];
        if($(this).html() == '确认'){
            let checkboxs =$('#table_table input[type=checkbox]:not("#checkAll")');
            for (let i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    delete_arr.push( $(checkboxs[i]).closest('tr[data-index]').attr('data-index') )
                }else{
                    continue;
                }
            }
            $.ajax({
                url:'/Admin/Power/multiDelPower',
                type:'post',
                data:{
                    power_id: delete_arr
                },
                success:function(data){
                    if(data.code==1){
                        for(let r = 0; r < delete_arr.length; r++){
                            $('#table_table').children('tbody').children(`[data-index=${delete_arr[r]}]`).remove();
                        }
                        $('#delete').removeClass('active')
                        window.location.href = `/Admin/Power/index`//强制刷新
                    }else{
                        $('#yz_modal').html(data.msg)
                        $('#yz_modal').addClass('active')
                        tipShow()
                        return
                    }
                    checkBox()
                }
            })
        }else{
            $('#delete').removeClass('active')
        }

    })
    // 当点击编辑按钮时
    $('#table_table').on('click','.edit_table',function(e){
        e.preventDefault()
        var edit_box = $(this).attr('href')
        let edit_id= $(this).closest('tr[data-index]').attr('data-index')
        // console.log(edit_id)
        if($(this).html()=='编辑'){
            $.ajax({
                url:'/Admin/Power/editPower',
                type:'get',
                data:{
                    id:edit_id
                },
                success:function(data){
                    if(data.code==1){
                        let datas = data.data;
                        // console.log(datas)
                        $(`[lll=${edit_box}]`).find('[add_name="edit_time"]').val(datas.power_time);
                        $(`[lll=${edit_box}]`).find('[add_name="edit_yf_electric"]').val(datas.dev_count);
                        $(`[lll=${edit_box}]`).find('[add_name="edit_fz_electric"]').val(datas.fz_count);
                        $(`[lll=${edit_box}]`).find('[add_name="edit_sum_electric"]').val(datas.total_count);
                        $(`[lll=${edit_box}]`).find('[add_name="edit_electricPrice"]').val(datas.power_uprice);
                        $(`[lll=${edit_box}]`).find('[add_name="edit_electricMoney"]').val(datas.power_total);
                        let fileBtn = $(`[lll=${edit_box}]`).find('[add_name="edit_file"]');
                        let imgs = datas.imgs;
                        let imgHTML = '';
                        let imgEditArr2 = []
                        for(var imgi=0;imgi<imgs.length;imgi++){
                            imgHTML += `
                                <li class="pz_file_list_text">
                                    <span>${imgs[imgi].fname} ${imgs[imgi].fsize}kb</span>
                                    <i class="iconfont icon-cha"></i>
                                </li>
                        `
                            let imgEditArr = []
                            imgEditArr.push(imgs[imgi].base64)
                            imgEditArr.push(imgs[imgi].fname)
                            imgEditArr.push(imgs[imgi].fsize)
                            imgEditArr2.push(imgEditArr)
                        }
                        $(fileBtn).parent().siblings('.pz_file_list').html(imgHTML);

                        $(`[lll=${edit_box}]`).addClass('active')
                        window.sessionStorage['edit_id']=edit_id
                        let edit_img_box = {
                            imgEditArr2:imgEditArr2
                        }

                        window.sessionStorage['edit_img_box'] = JSON.stringify(edit_img_box)
                        // console.log(window.sessionStorage['edit_img_box'])
                        //
                    }else{

                    }
                }
            })
        }else if($(this).html()=='查看'){
            $.ajax({
                url:'/Admin/Power/editPower',
                type:'get',
                data:{
                    id:edit_id
                },
                success:function(data){
                    if(data.code==1){
                        let datas = data.data;
                        let showimgHTML = ''
                        for(var showimgi=0;showimgi<datas.imgs.length;showimgi++){
                            showimgHTML += `
                                <li><a data-magnify="gallery" href="${datas.imgs[showimgi].img}"><img src="${datas.imgs[showimgi].thumb}"></a></li>
                            `
                        }
                        $('#look_img').children('.look_img_list').html(showimgHTML)

                    }else{

                    }
                }
            })
            $(`[lll=${edit_box}]`).addClass('active')
        }else if($(this).html()=='取消核算'){
            let cancel_hesuan_id = $(this).closest('tr[data-index]').attr('data-index')
            let that = this
            $.ajax({
                url: '/Admin/Power/canelPow',
                type: 'get',
                data: {
                    id: cancel_hesuan_id
                },
                success: function(data){
                    if(data.code==1){
                        // console.log(1)
                        $(that).closest('tr[data-index]').find('input').removeAttr('disabled')
                        $(that).html('编辑')
                        $(that).attr('href','edit_people')
                    }
                }
            })
        }

    })
    //当凭证查看点击确定的时候
    $('#look_img').on('click','.btn-success',function(){
        $('#look_img').removeClass('active')
    })
    //上传凭证
    let fileArr = [];

    let IMG_arr2 = [];
    $('.hidden_input').on('change',function(){
        // console.log(window.sessionStorage['edit_id'])
        // let oldedit_id = window.sessionStorage['edit_id']

        let data = this.files;
        for(var i =0;i<data.length;i++){
            let fileReader = new FileReader();
            fileReader.readAsDataURL(data[i]);
            let size = Math.round(data[i].size/1024);
            let name = data[i].name;
            let pz_file_listHTML = $(this).parent().siblings('.pz_file_list').html();
            pz_file_listHTML += `<li class="pz_file_list_text">
                                    <span>${name} ${size}kb</span>
                                    <i class="iconfont icon-cha"></i>
                                </li>
                                 `
            $(this).parent().siblings('.pz_file_list').html(pz_file_listHTML);
            fileReader.onload = function (e){
                let url = this.result;//上传文件的URL
                // let img_btnSrc = url.indexOf('4');
                // let img = url.substring(img_btnSrc + 2);
                let IMG_arr = [];
                IMG_arr.push(url);
                IMG_arr.push(name);
                IMG_arr.push(size);

                IMG_arr2.push(IMG_arr)
            }

        }
    })
    //当删除某个凭证的时候
    $('.pz_file_list').on('click','i',function(e){
        e.preventDefault();
        fileArr.splice($(this).parent().index(),1);
        // IMG_arr.splice($(this).parent().index(),1);
        IMG_arr2.splice($(this).parent().index(),1);
        let edit_img_box_old = JSON.parse(window.sessionStorage['edit_img_box']).imgEditArr2
        edit_img_box_old.splice($(this).parent().index(),1);
        let edit_img_box = {
            imgEditArr2:edit_img_box_old
        }
        window.sessionStorage['edit_img_box'] = JSON.stringify(edit_img_box)
        $(this).parent().remove()
    })

    /*金额 自动计算*/
    $('[add_name=add_fz_electric]').blur(function(){
        let add_fz_electric = $(this).val();
        let add_yf_electric = $(this).closest('[lll]').find('[add_name=add_yf_electric]').val();
        if(add_fz_electric&&add_yf_electric){
            let add_sum_electric = Number(add_fz_electric)+Number(add_yf_electric)
            $(this).closest('[lll]').find('[add_name=add_sum_electric]').val(add_sum_electric.toFixed(3))
        }else{
            $(this).closest('[lll]').find('[add_name=add_sum_electric]').val('')
            return
        }
    })
    /*电费金额 自动计算*/
    $('[add_name=add_electricPrice]').blur(function(){
        let add_electricPrice = $(this).val();
        let add_sum_electric = $(this).closest('[lll]').find('[add_name=add_sum_electric]').val();
        if(add_electricPrice&&add_sum_electric){
            let add_electricMoney = Number(add_electricPrice)*Number(add_sum_electric)
            $(this).closest('[lll]').find('[add_name=add_electricMoney]').val(add_electricMoney.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=add_electricMoney]').val('')
            return
        }
    })
    // 确认按钮点击时
    $('#add_btn').click(function(){
        let add_time = $(this).closest('[lll]').find('[add_name=add_time]').val()
        let add_yf_electric = $(this).closest('[lll]').find('[add_name=add_yf_electric]').val()
        let add_fz_electric = $(this).closest('[lll]').find('[add_name=add_fz_electric]').val()
        let add_sum_electric = $(this).closest('[lll]').find('[add_name=add_sum_electric]').val()
        let add_electricPrice = $(this).closest('[lll]').find('[add_name=add_electricPrice]').val()
        let add_electricMoney = $(this).closest('[lll]').find('[add_name=add_electricMoney]').val()
        let add_file = IMG_arr2

        if(add_time == '' || add_yf_electric == '' || add_fz_electric == '' || add_sum_electric == '' || add_electricPrice == '' || add_electricMoney == ''){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        //防止重复点击按钮
            if( $(this).attr('lock') ) return
            $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/Power/addPower',
            type:'post',
            data:{
                power_time:add_time,
                dev_count:add_yf_electric,
                fz_count:add_fz_electric,
                total_count:add_sum_electric,
                power_uprice:add_electricPrice,
                power_total:add_electricMoney,
                vimgs:add_file
            },
            success:function(data){
                if(data.code==1){
                    // var peopleTableHTML = $('#table_table').children('tbody').html()
                    let peopleTableHTML = `
                    <tr data-index="${data.id}">
                            <td><input type="checkbox" class="checkboxStyle"></td>
                            <td data-name="edit_time">${add_time}</td>
                            <td data-name="edit_yf_electric">${add_yf_electric}</td>
                            <td data-name="edit_fz_electric">${add_fz_electric}</td>
                            <td data-name="edit_sum_electric">${add_sum_electric}</td>
                            <td data-name="edit_electricPrice">${add_electricPrice}</td>
                            <td data-name="edit_electricMoney">${add_electricMoney}</td>
                            <td data-name="edit_file"><a href="look_img" class="edit_table">查看</a></td>
                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                        </tr>
            `
                    $('#table_table').children('tbody').prepend(peopleTableHTML)

                    $(that).closest('[lll]').find('[add_name]').val('')
                    $(that).closest('[lll]').removeClass('active')
                    IMG_arr2 = []
                }else{
                    $('#yz_modal').html(data.msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    // return
                }
                $(that).removeAttr('lock')
            }
        })

    })
    // 确认并新增按钮点击时
    $('#add_AddNew_btn').click(function(){
        let add_time = $(this).closest('[lll]').find('[add_name=add_time]').val()
        let add_yf_electric = $(this).closest('[lll]').find('[add_name=add_yf_electric]').val()
        let add_fz_electric = $(this).closest('[lll]').find('[add_name=add_fz_electric]').val()
        let add_sum_electric = $(this).closest('[lll]').find('[add_name=add_sum_electric]').val()
        let add_electricPrice = $(this).closest('[lll]').find('[add_name=add_electricPrice]').val()
        let add_electricMoney = $(this).closest('[lll]').find('[add_name=add_electricMoney]').val()
        let add_file = IMG_arr2

        if(add_time == '' || add_yf_electric == '' || add_fz_electric == '' || add_sum_electric == '' || add_electricPrice == '' || add_electricMoney == ''){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        //防止重复点击按钮
            if( $(this).attr('lock') ) return
            $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/Power/addPower',
            type:'post',
            data:{
                power_time:add_time,
                dev_count:add_yf_electric,
                fz_count:add_fz_electric,
                total_count:add_sum_electric,
                power_uprice:add_electricPrice,
                power_total:add_electricMoney,
                vimgs:add_file
            },
            success:function(data){
                if(data.code==1){
                    // var peopleTableHTML = $('#table_table').children('tbody').html()
                    let peopleTableHTML = `
                    <tr data-index="${data.id}">
                            <td><input type="checkbox" class="checkboxStyle"></td>
                            <td data-name="edit_time">${add_time}</td>
                            <td data-name="edit_yf_electric">${add_yf_electric}</td>
                            <td data-name="edit_fz_electric">${add_fz_electric}</td>
                            <td data-name="edit_sum_electric">${add_sum_electric}</td>
                            <td data-name="edit_electricPrice">${add_electricPrice}</td>
                            <td data-name="edit_electricMoney">${add_electricMoney}</td>
                            <td data-name="edit_file"><a href="look_img" class="edit_table">查看</a></td>
                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                        </tr>
            `
                    $('#table_table').children('tbody').prepend(peopleTableHTML)

                    $(that).closest('[lll]').find('[add_name]').val('')
                    IMG_arr2 = []
                }else{
                    $('#yz_modal').html(data.msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    // return
                }
                $(that).removeAttr('lock')
            }
        })
    })

    /*金额 自动计算*/
    $('[add_name=edit_fz_electric]').blur(function(){
        let edit_fz_electric = $(this).val();
        let edit_yf_electric = $(this).closest('[lll]').find('[add_name=edit_yf_electric]').val();
        if(edit_fz_electric&&edit_yf_electric){
            let edit_sum_electric = Number(edit_fz_electric)+Number(edit_yf_electric)
            $(this).closest('[lll]').find('[add_name=edit_sum_electric]').val(edit_sum_electric.toFixed(3))
        }else{
            $(this).closest('[lll]').find('[add_name=edit_sum_electric]').val('')
            return
        }
    })
    /*电费金额 自动计算*/
    $('[add_name=edit_electricPrice]').blur(function(){
        let edit_electricPrice = $(this).val();
        let edit_sum_electric = $(this).closest('[lll]').find('[add_name=edit_sum_electric]').val();
        if(edit_electricPrice&&edit_sum_electric){
            let edit_electricMoney = Number(edit_electricPrice)*Number(edit_sum_electric)
            $(this).closest('[lll]').find('[add_name=edit_electricMoney]').val(edit_electricMoney.toFixed(2))
        }else{
            $(this).closest('[lll]').find('[add_name=edit_electricMoney]').val('')
            return
        }
    })
    // 保存按钮点击时
    $('#save_btn').click(function(){
        let edit_time = $(this).closest('[lll]').find('[add_name=edit_time]').val()
        let edit_yf_electric = $(this).closest('[lll]').find('[add_name=edit_yf_electric]').val()
        let edit_fz_electric = $(this).closest('[lll]').find('[add_name=edit_fz_electric]').val()
        let edit_sum_electric = $(this).closest('[lll]').find('[add_name=edit_sum_electric]').val()
        let edit_electricPrice = $(this).closest('[lll]').find('[add_name=edit_electricPrice]').val()
        let edit_electricMoney = $(this).closest('[lll]').find('[add_name=edit_electricMoney]').val()
        // let edit_file = $(this).closest('[lll]').find('[add_name=edit_file]').val()
        // console.log(IMG_arr2)
        // console.log(JSON.parse(window.sessionStorage['edit_img_box']).edit_id)
        // console.log(JSON.parse(window.sessionStorage['edit_img_box']).imgEditArr2)
        if(edit_time == '' || edit_fz_electric == '' || edit_fz_electric == '' || edit_sum_electric == '' || edit_electricPrice == '' || edit_electricMoney == ''){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        //防止重复点击按钮
            if( $(this).attr('lock') ) return
            $(this).attr('lock','lock')

        let edit_id = window.sessionStorage['edit_id']
        let that = this
        let edit_file = JSON.parse(window.sessionStorage['edit_img_box']).imgEditArr2.concat(IMG_arr2)
        console.log(edit_file)

        $.ajax({
            url:'/Admin/Power/editPower',
            type:'post',
            data:{
                id:edit_id,
                power_time:edit_time,
                dev_count:edit_yf_electric,
                fz_count:edit_fz_electric,
                total_count:edit_sum_electric,
                power_uprice:edit_electricPrice,
                power_total:edit_electricMoney,
                vimgs:edit_file
            },
            success:function(data){
                // console.log(data)
                if(data.code==1){
                    let tableHTML = $('#table_table').find(`tr[data-index=${edit_id}]`)
                    tableHTML.children('[data-name=edit_time]').html(edit_time)
                    tableHTML.children('[data-name=edit_yf_electric]').html(edit_yf_electric)
                    tableHTML.children('[data-name=edit_fz_electric]').html(edit_fz_electric)
                    tableHTML.children('[data-name=edit_sum_electric]').html(edit_sum_electric)
                    tableHTML.children('[data-name=edit_electricPrice]').html(edit_electricPrice)
                    tableHTML.children('[data-name=edit_electricMoney]').html(edit_electricMoney)
                    $(that).parent().parent().removeClass('active')
                    window.sessionStorage['edit_id'] = ''
                    let edit_img_box = {
                        imgEditArr2:[]
                    }

                    window.sessionStorage['edit_img_box'] = JSON.stringify(edit_img_box)
                    // console.log(JSON.stringify(edit_img_box))
                }
                $(that).removeAttr('lock')
            }
        })

    })
    // 取消按钮点击时
    $('.button_list').on('click','button',function(){
        if($(this).hasClass('cancel_btn')){

            $(this).closest('[lll]').find('[add_name]').val('')
            $(this).closest('[lll]').find('.pz_file_list').html('')
            IMG_arr2 = []
            let edit_img_box = {
                imgEditArr2:[]
            }

            window.sessionStorage['edit_id'] = ''
            window.sessionStorage['edit_img_box'] = JSON.stringify(edit_img_box)
            $(this).closest('[lll]').removeClass('active')
        }
    })

    let msg = '文件正在上传，请勿重复点击！'

    // 上传文件
    $('#file_upload').change(function (e) {
        $(this).siblings('.import_tip_btn_box').find('button').removeClass('btn-grey').addClass('btn-success')
        msg = '文件正在上传，请勿重复点击！'
        $(this).siblings('.import_tip_btn_box').find('button').removeAttr('lock')
    })
    $('#import').find('button').click(function(e){
        "use strict";
        e.preventDefault()
        if($(this).hasClass('btn-success')){
            if($(this).html()=='确定导入'){
                //防止重复点击按钮
                if( $(this).attr('lock') ){
                    $('#yz_modal').html(msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    return
                }
                $(this).attr('lock','lock')
                let that = this
                
                var formData = new FormData($("#file_form")[0]);
                $.ajax({
                    async : false,
                    cache : false,
                    type : "post",
                    data : formData,
                    url : '/Admin/Power/importPower',
                    dataType : 'json',
                    contentType: false, //必须
                    processData: false, //必须
                    success : function(data) {
                        if(data.code==1){
                            $('#import').removeClass('active')
                            window.location.href = `/Admin/Power/index`//强制刷新
                            $(that).removeAttr('lock')
                        }else{
                            msg = data.msg
                            $('#yz_modal').html(msg)
                            $('#yz_modal').addClass('active')
                            tipShow()
                        }
                    }
                })
            }
        }

    })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            // $('#yz_modal').removeClass('active')
            // $('#yz_modal').addClass('fadeOut')
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox)
        },2000)
    }
    //关闭所有已选择的框框
    function checkBox(){
        var checkboxs =$('input[type=checkbox]');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                continue;
            }else{
                $(checkboxs[i]).attr('checked',false)
            }
        }
    }

    //当点击区域不在导入弹框中时则关闭弹框
    $(document).click(function(e){
        let $this = $(e.target);
        if($this.closest('#import').length==0){
            if($this.attr('href') != '#import' && $this.children().attr('href') != '#import'){
                $('#import').removeClass('active');
            }
        }
    })

    //拖动拖动拖动
        let add_box =document.getElementById("add_people");
        let edit_box =document.getElementById("edit_people");
        add_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='add_people'){
                ev =ev ||event;
                let oLeft = add_box.offsetLeft;
                let oTop = add_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                add_box.onmousemove =function (ev){
                    ev = ev || event;
                    add_box.style.left =ev.clientX-a+'px';
                    add_box.style.top =ev.clientY-b+'px';
                    $(add_box).css({'cursor':'default'})
                }
            }
            
        }
        edit_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='edit_people'){
                ev =ev ||event;
                let oLeft = edit_box.offsetLeft;
                let oTop = edit_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                edit_box.onmousemove =function (ev){
                    ev = ev || event;
                    edit_box.style.left =ev.clientX-a+'px';
                    edit_box.style.top =ev.clientY-b+'px';
                    $(edit_box).css({'cursor':'default'})
                }
            }
        
        }
        document.onmouseup =function(){
            add_box.onmousemove =function(){
                null;
            }
            edit_box.onmousemove =function(){
                null;
            }
        }
})